package com.zds.zhouyi.util;

import android.icu.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class StringUtil {
    public static String getDateByTimestamp(long timestamp) {
        // 创建一个SimpleDateFormat实例
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        // 使用format方法将时间戳转换为日期字符串
        return sdf.format(new Date(timestamp));
    }


    private static final String[] CN_NUMERIC = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
    private static final String[] CN_NUMERIC_UNITS = {"", "十", "百", "千"};

    public static String numberToChinese(int num) {
        StringBuilder sb = new StringBuilder();
        int unit = 0;
        while (num > 0) {
            int n = num % 10;
            if (n == 0) {
                if (sb.length() > 0 && sb.charAt(0) != '零') {
                    sb.insert(0, '零');
                }
            } else {
                if (unit == 1 && n == 1) {
                    //举例：十一 不用改成 一十一
                    sb.insert(0, CN_NUMERIC_UNITS[unit]);
                } else {
                    sb.insert(0, CN_NUMERIC[n] + CN_NUMERIC_UNITS[unit]);
                }
            }
            unit++;
            num = num / 10;
        }
        return sb.toString();
    }


}
